//
//  HAODE
//
//  Created by panquanReabam.com on 15/9/23.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "BusinessWhsInAddViewController.h"
#import "ZJSwitch.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "UIImageView+WebCache.h"
#import "daogouview.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "shouyinCell.h"
#import "huiyuandengjiViewController.h"
#import "shangpingview.h"
#import "peisongleibieViewController.h"
#import "ToResiduePayViewController.h"
#import "addhuiyuanViewController.h"
#import "huiyuanDetailsViewController.h"
#import "BusinessCouponDetailViewController.h"
#import "saoyisaoViewController.h"
#import "BusinessMemberAddressViewController.h"
#import "BusinessShelfListViewController.h"
#import "BusinessWhsInListViewController.h"
#import "BusinessWhsOutListViewController.h"
#import "BusinessCheckVouchListViewController.h"
#import "BusinessWhsWhsItemListViewController.h"
#import "reasonTypeViewController.h"
#import "ClearFB.h"
@interface BusinessWhsInAddViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,UISearchBarDelegate,UIScrollViewDelegate>

@property (strong, nonatomic) NSString*GuideCode;
@property (strong, nonatomic) NSString*whsInTypeCode;
@property (strong, nonatomic) NSString*whsId;
@property (strong, nonatomic) NSString*WhsInType;


@end

@implementation BusinessWhsInAddViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    UIButton* sxBtn;
    UIButton*jiantouBtn;
    UIButton*cardBtn;
    float lastContentOffset;
    UITextField*searchTextField;
    UITextField*zhekoujineTextFied;
    UITextField*songhuoTextFied;
    UITextField*anzhuangTextFied;
    UIButton*daogouname;
    daogouview*daogouView;
    UIButton*leixingBtn;
    UIButton*leixingBtn1;
    UIView*view;
    UIView*view1;
    shangpingview*shangpingView;
    UIScrollView*mainScroll;
    UIScrollView*MYmainScroll;
    UILabel*huiyuanname;
    UIButton *tureBtn;
    UILabel*dingdanhao1;
    BOOL saveAccount;
    UIButton *xuanze;
    UIButton*jiagemingxi1;
    UIButton*DiscountRateSatBtn;
    NSMutableArray* arrrss;
    NSMutableArray* arrrss1;
    
    NSMutableArray* codearr;
    NSMutableArray* contenarrr;
    NSMutableArray*DiscountRatecode ;
    NSMutableArray*DiscountRatecontent ;
    ZJSwitch *switch2;
    UITextField*dinjinjineTextFied;
    UIButton*EarnestRateSatBtn;
    UILabel* weightke;
    UIView*view2;
    UIView*view3;
    UIView*view4;
    UIView*view5;
    UIView*view6;
    UITextView* tv;
    UILabel * label;
    UIImageView*imagess;
    UILabel*shengyuzhifujiage1;
    UIButton*anzhuangSatBtn;
    UIButton*peisongSatBtn;
    UIView* myToolBar;
    UIButton*hejiMoney;
    NSString *userToken;

}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    //[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    userToken=@"";
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    userToken = [user objectForKey:@"tokenId"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    //会员信息
    
    self.title = self.titleName;
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     backColor,
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    self.whsId=commdity.whsId;
  
    [leixingBtn1 setTitle:commdity.whsName forState:UIControlStateNormal];
    
    if ([self.Whs isEqualToString:@"Shelf"]) {
     
    }else{
        
    
    [leixingBtn setTitle:commdity.content forState:UIControlStateNormal];
    
    }
}








- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    
    commdity=[HAODEsingleton shared];
    
    
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, 300/2-10)];
    view.backgroundColor=zuiqianhuicolor;
    view.layer.borderWidth = 0.35;
    view.layer.borderColor = qianhuicolor.CGColor;
    [self.view addSubview:view];
    
    
    view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 88/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    
    
    UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth, 0.35)];
    line1.backgroundColor=qianhuicolor;
    [view addSubview:line1];
    UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 40, 88/2)];
    duogou.text=[NSString stringWithFormat:@"员工"];
    duogou.textColor=zhonghuiColor;
    duogou.font=[UIFont systemFontOfSize:15];
    [view addSubview:duogou];
    
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString* UserName = [user1 objectForKey:@"userName"];
    self.GuideCode = [user1 objectForKey:@"UserCode"];
    daogouname=[[UIButton alloc]initWithFrame:CGRectMake(50, 0,ScreenWidth-100,88/2)];
    [daogouname setTitle:UserName forState:UIControlStateNormal];
    daogouname.titleLabel.font=[UIFont systemFontOfSize:15];
    daogouname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [daogouname setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view addSubview:daogouname];

    
    view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 175/2)];
    view2.backgroundColor=[UIColor whiteColor];
    view2.layer.borderWidth = 0.35;
    view2.layer.borderColor = qianhuicolor.CGColor;
    [view addSubview:view2];
    
    UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(15,  175/2/2, ScreenWidth-30, 0.35)];
    line3.backgroundColor=qianhuicolor;
    [view2 addSubview:line3];
    
    
    UILabel*leixing=[[UILabel alloc]initWithFrame:CGRectMake(15,0, 200, 175/2/2)];
    leixing.text=@"类型";
    leixing.textColor=zhonghuiColor;
    leixing.font=[UIFont systemFontOfSize:contenfot];
    [view2 addSubview:leixing];
    

    leixingBtn=[[UIButton alloc]initWithFrame:CGRectMake(50,  0, ScreenWidth-100,175/2/2)];
    leixingBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    leixingBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [leixingBtn addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [leixingBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:leixingBtn];
    
    UIButton*jiantouBtn12 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,15,8, 13)];    [jiantouBtn12 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [jiantouBtn12 addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:jiantouBtn12];

    
    UILabel*leixing1=[[UILabel alloc]initWithFrame:CGRectMake(15,175/2/2, 200, 175/2/2)];
    leixing1.text=@"仓库";
    leixing1.textColor=zhonghuiColor;
    leixing1.font=[UIFont systemFontOfSize:contenfot];
    [view2 addSubview:leixing1];
    
    leixingBtn1=[[UIButton alloc]initWithFrame:CGRectMake(50,  175/2/2, ScreenWidth-100,175/2/2)];
    [leixingBtn1 setTitle:@"                                                             " forState:UIControlStateNormal];
    leixingBtn1.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    leixingBtn1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [leixingBtn1 addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
    [leixingBtn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:leixingBtn1];
    
    UIButton*jiantouBtn121 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,175/2/2+15,8, 13)];
    [jiantouBtn121 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [jiantouBtn121 addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:jiantouBtn121];


    
 
    MYmainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,view.bottom, ScreenWidth, ScreenHeight-300/2)];
    [MYmainScroll setBackgroundColor: zuiqianhuicolor];
    MYmainScroll.delegate = self;
    MYmainScroll.userInteractionEnabled = YES;
    MYmainScroll.scrollEnabled = YES;
    MYmainScroll.showsVerticalScrollIndicator = FALSE;
    MYmainScroll.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:MYmainScroll];
    
    view3=[[UIView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 45)];
    view3.backgroundColor=[UIColor whiteColor];
    [MYmainScroll addSubview:view3];
    UILabel *lineL=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.35)];
    lineL.backgroundColor=qianhuicolor;
    [view3 addSubview:lineL];
                
    UILabel*shangpingxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 10, 80, 45)];
    shangpingxinxi.text=@"商品信息";
    shangpingxinxi.textColor=[UIColor blackColor];
    shangpingxinxi.font=[UIFont systemFontOfSize:15];
    [MYmainScroll addSubview:shangpingxinxi];
                
                

    
                
    UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
    lineLabel1.backgroundColor=qianhuicolor;
    [view3 addSubview:lineLabel1];
                
    
    if (commdity.ItemName44.count>0) {
                    
                    for (int i = 0; i<commdity.ItemName44.count; i++) {
                        
                        shangpingView = [[shangpingview alloc]initWithFrame:CGRectMake(0, view3.bottom+(120*i), ScreenWidth, 120)];
                        shangpingView.backgroundColor=[UIColor whiteColor];
                        [shangpingView.headImageFull setImageWithURL:[commdity.ImageUrl44 objectAtIndex:i]  placeholderImage:[UIImage imageNamed:@""]];
                        [shangpingView.headImageFull.layer setCornerRadius:6.0];
                        [shangpingView.headImageFull.layer setBorderWidth:0.3];
                        [shangpingView.headImageFull.layer setMasksToBounds:YES];
                        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
                        [shangpingView.headImageFull.layer setBorderColor:colorref2];//边框颜色
                        
                        shangpingView.itemName.text=[NSString stringWithFormat:@"%@%@",[commdity.ItemCode44 objectAtIndex:i],[commdity.ItemName44 objectAtIndex:i]];
                        
                        shangpingView.quantity.text=[NSString stringWithFormat:@"数量 %@",[commdity.how44 objectAtIndex:i]];
                        
                        NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"数量 %@",[commdity.how44 objectAtIndex:i]]];
                        
                        [AttributedStr1 addAttribute:NSFontAttributeName
                         
                                               value:[UIFont systemFontOfSize:contenfot]
                         
                                               range:NSMakeRange(0, 3)];
                        
                        [AttributedStr1 addAttribute:NSForegroundColorAttributeName
                         
                                               value:zhonghuiColor
                         
                                               range:NSMakeRange(0, 3)];
                        
                        
                        shangpingView.quantity.attributedText = AttributedStr1;
                        
                        
                        NSNumber*Total =[commdity.Price44 objectAtIndex:i];
                        
                        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                        [numberFormatter setPositiveFormat:@"###,##0.00;"];
                        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
                        shangpingView.dealPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
                        shangpingView.dealPrice.textColor=hongsecolor;
                        
                        
                        NSMutableAttributedString *AttributedStr11 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@",formattedNumberString]];
                        
                        [AttributedStr11 addAttribute:NSFontAttributeName
                         
                                               value:[UIFont systemFontOfSize:contenfot]
                         
                                               range:NSMakeRange(0, 1)];
                        
                        [AttributedStr11 addAttribute:NSForegroundColorAttributeName
                         
                                               value:hongsecolor
                         
                                               range:NSMakeRange(0, 1)];
                        
                        
                        shangpingView.dealPrice.attributedText = AttributedStr11;
                        shangpingView.itemType.text=[NSString stringWithFormat:@"%@",[commdity.specName44 objectAtIndex:i]];
                        
                        
                        
                        
                        if (i==arrrss.count-1) {
                            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
                            lineLabel1.backgroundColor=qianhuicolor;
                            [shangpingView addSubview:lineLabel1];
                        }else{
                            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
                            lineLabel1.backgroundColor=qianhuicolor;
                            [shangpingView addSubview:lineLabel1];
                            
                            
                        }
                        
                        [MYmainScroll addSubview:shangpingView];
                        
                    }
                    
                }
                
    
                
                UILabel*lineLab1=[[UILabel alloc] initWithFrame:CGRectMake(0, shangpingView.bottom+10-0.35, ScreenWidth, 0.35)];
                lineLab1.backgroundColor=qianhuicolor;
                [view addSubview:lineLab1];
    
                
                view6=[[UIView alloc]initWithFrame:CGRectMake(0, shangpingView.bottom+10, ScreenWidth, 100)];
                view6.backgroundColor=[UIColor whiteColor];
                view6.layer.borderWidth = 0.35;
                view6.layer.borderColor = qianhuicolor.CGColor;
                [MYmainScroll addSubview:view6];
    
                tv=[[UITextView alloc]init];
                tv.frame=CGRectMake(20, 10, ScreenWidth-40, 90);
                tv.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
                tv.scrollEnabled = YES;//是否可以拖动
                tv.delegate=self;
                tv.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
                tv.layer.borderWidth =0.0;
                CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
                CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
                //tv.keyboardType = UIKeyboardTypePhonePad;
                [tv.layer setBorderColor:tureBTncolorref111];//边框颜色
                tv.layer.cornerRadius =0;
                [view6 addSubview:tv];
                imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
                imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
                [tv addSubview:imagess];
                label=[[UILabel alloc]init];
                label.frame =CGRectMake(23, 7, ScreenWidth-60, 14);
                label.text = @"备注";
                label.textColor=zuiqianhuicolor;
                label.numberOfLines=0;
                label.font=[UIFont systemFontOfSize:14];
                label.enabled = NO;//lable必须设置为不可用
                label.backgroundColor = [UIColor clearColor];
                [tv addSubview:label];
                
                tv.inputAccessoryView = myToolBar;
    
                MYmainScroll.contentSize = CGSizeMake(ScreenWidth, view6.bottom+300);
                

    
    
    
    NSMutableArray*  sum=[[NSMutableArray alloc]init];
    
    for (int i=0; i<commdity.Price44.count; i++) {
        
        NSString *typeCode1 = [commdity.Price44 objectAtIndex:i];
        NSString *isSingle1 = [commdity.how44 objectAtIndex:i];
        
        [sum addObject:[NSString stringWithFormat:@"%.2f",  [typeCode1 doubleValue]*[isSingle1 doubleValue]]];
        
        
    }
    
    NSNumber *sum11 = [sum valueForKeyPath:@"@sum.floatValue"];
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",sum11];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    
    hejiMoney=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth*430/750, 45)];
    [hejiMoney setTitle:[NSString stringWithFormat:@"   合计 ¥ %@",formattedNumberString] forState:UIControlStateNormal];
    hejiMoney.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [hejiMoney setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    hejiMoney.alpha=0.8;
    hejiMoney.contentHorizontalAlignment=UIControlContentHorizontalAlignmentFill;
    hejiMoney.contentVerticalAlignment=UIControlContentVerticalAlignmentBottom;
    hejiMoney.titleLabel.font=[UIFont systemFontOfSize:18];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"   合计 ¥ %@",formattedNumberString]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:13]
     
                          range:NSMakeRange(0, 7)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor whiteColor]
     
                          range:NSMakeRange(0, 7)];
    
    
    hejiMoney.titleLabel.attributedText = AttributedStr;
    
    UIButton* shuliang=[[UIButton alloc]initWithFrame:CGRectMake(0, 9, ScreenWidth*430/750, 11)];
    NSNumber *sum1 = [commdity.how44 valueForKeyPath:@"@sum.floatValue"];
    
    [shuliang setTitle:[NSString stringWithFormat:@"   共 %@ 件商品",sum1] forState:UIControlStateNormal];
    shuliang.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [shuliang setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shuliang.titleLabel.font=[UIFont systemFontOfSize:11];
    shuliang.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [hejiMoney addSubview:shuliang];
    
    [self.view addSubview:hejiMoney];
    
    
    UIButton*dise=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-3, ScreenWidth*430/750, 3)];
    dise.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
    [self.view addSubview:dise];

    
    
    
    
    
    
    
    UIButton*buyBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-48, ScreenWidth*320/750, 48)];
    [buyBtn2 setTitle:@"确定" forState:UIControlStateNormal];
    buyBtn2.backgroundColor=luseColor;
    [buyBtn2 addTarget:self action:@selector(shouying:) forControlEvents:UIControlEventTouchUpInside];
                
    [buyBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:buyBtn2];
                
    if ([self.Whs isEqualToString:@"Shelf"]) {
        [leixingBtn setTitle:@"上架" forState:UIControlStateNormal];
        
        self.shelfType=@"U";
    }else{
        

    }
    
    
    


   
}
//陈列 入库 出库
-(void)shouying:(UIButton *)sender {
    
    
    if ([leixingBtn.titleLabel.text length] < 1) {
        [self showAlertMessage:@"请选择类型！"];
    } else{

    
    
    
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            if (Token ==nil) {
                Token=@"dd";
            }
            
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
            [params setValue:self.whsId forKey:@"whsId"];
    
    if ([self.Whs isEqualToString:@"Shelf"]) {
    [params setValue:self.shelfType forKey:@"shelfType"];
    
    }else{
    
        if ([self.Whs isEqualToString:@"WhsOut"]) {
        [params setValue:commdity.code forKey:@"whsOutTypeCode"];
    }else{
        [params setValue:commdity.code forKey:@"whsInTypeCode"];
        
        }
   
    }
    
            NSMutableArray *mDocumentLine=[NSMutableArray array];
      NSLog(@"33333333====%@",commdity.currentSpecId44);
    
            for (int i=0; i<commdity.currentSpecId44.count; i++) {
        
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                NSString *itemId = [commdity.Itemid44 objectAtIndex:i];
                NSString *quantity =[commdity.how44 objectAtIndex:i];
                NSString *specId =[NSString stringWithFormat:@"%@",[commdity.currentSpecId44 objectAtIndex:i]];
                
                
                [dic setValue:quantity forKey:@"quantity"];
                [dic setValue:itemId forKey:@"itemId"];
                if ([specId isEqualToString:@""]) {
                    
                }else{
                   
                    if ([specId isEqualToString:@"<null>"]) {
                        specId=@"";
                    }
                    [dic setValue:specId forKey:@"specId"];
                }
               
                [mDocumentLine addObject:dic];
        
        
            }
    
            [params setValue:mDocumentLine  forKey:@"itemList"];
            [params setValue:tv.text  forKey:@"remark"];
    
            NSLog(@"33333333====%@",params);
    
    
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            
            
            [HttpRequest requestData:[NSString stringWithFormat:@"Business/%@/Add",self.Whs] params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
//                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
         
                        [ClearFB clearUserData:userToken typeString:_saveTypeStr];
                        
                        if ([self.Whs isEqualToString:@"Shelf"]) {
                            BusinessShelfListViewController *detailViewController = [[BusinessShelfListViewController alloc] init];
                           
                            [self.navigationController pushViewController:detailViewController animated:YES];
                        }
                        
                        
                        if ([self.Whs isEqualToString:@"WhsOut"]) {
                            BusinessWhsOutListViewController *detailViewController = [[BusinessWhsOutListViewController alloc] init];
                            
                            [self.navigationController pushViewController:detailViewController animated:YES];
                        }

                        if ([self.Whs isEqualToString:@"WhsIn"]) {
                            BusinessWhsInListViewController *detailViewController = [[BusinessWhsInListViewController alloc] init];
                            
                            [self.navigationController pushViewController:detailViewController animated:YES];
                        }
                   
                        if ([self.Whs isEqualToString:@"CheckVouch"]) {
                            BusinessCheckVouchListViewController *detailViewController = [[BusinessCheckVouchListViewController alloc] init];
                            
                            [self.navigationController pushViewController:detailViewController animated:YES];
                        }
                        
                        
                        
                        
                        
                        
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败 这条数据在维护！" view:self.view];
                }
                
            }];
   
    }
}

-(void)xuanzhidaogou1:(UIButton*)sender{

    
    BusinessWhsWhsItemListViewController *detailViewController = [[BusinessWhsWhsItemListViewController alloc] init];
    detailViewController.codeArray=codearr;
    detailViewController.contentArray=contenarrr;
    [self.navigationController pushViewController:detailViewController animated:YES];

    
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex == 1) {
       

        [leixingBtn setTitle:@"下架" forState:UIControlStateNormal];
        self.shelfType=@"D";
        
        
    }
    if (buttonIndex == 0) {
        [leixingBtn setTitle:@"上架" forState:UIControlStateNormal];
        self.shelfType=@"U";
        
    }
    
    
}

-(void)xuanzhidaogou:(UIButton*)sender{
    
    
    if ([self.Whs isEqualToString:@"Shelf"]) {
        
        
        UIAlertView*alt1 = [[UIAlertView alloc] initWithTitle:@"请选择陈列类型" message:nil delegate:self cancelButtonTitle:@"上架" otherButtonTitles:@"下架", nil];
        [alt1 show];
        
        
        
    }else{
    
    
    
        
        reasonTypeViewController *detailViewController = [[reasonTypeViewController alloc] init];
        detailViewController.optionName=self.Type;
        
        detailViewController.titlename=@"选择类型";
        [self.navigationController pushViewController:detailViewController animated:YES];
  
        
        
    
       
    }
    
}
-(void)closeKeyBoad
{
    [mainScroll removeFromSuperview];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    MYmainScroll .frame =CGRectMake(0,view.bottom, ScreenWidth, ScreenHeight-300/2);
    [UIView commitAnimations];
    
    [tv resignFirstResponder];
}
-(void)daogouView:(UIButton *)sender{
    
    
    self.whsInTypeCode=[[arrrss objectAtIndex:sender.tag]objectForKey:@"code"];
//    NSLog(@"%@",self.DocType);
    
  
    
    leixingBtn.titleLabel.text=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
}
-(void)daogouView1:(UIButton *)sender{
    
    
      self.whsId=[[arrrss1 objectAtIndex:sender.tag]objectForKey:@"id"];
    //    NSLog(@"%@",self.DocType);

    leixingBtn1.titleLabel.text=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    MYmainScroll .frame =CGRectMake(0, -100, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
    //self.examineText =  textView.text;
    
    
    if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [tv addSubview:imagess];
        label.text = @"备注";
        
    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}


//回收键盘
-(void)OnTapDone{
    [tv resignFirstResponder];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    MYmainScroll .frame =CGRectMake(0,view.bottom, ScreenWidth, ScreenHeight-300/2);
    [UIView commitAnimations];

}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}


@end
